package com.heima.article.feign;

import com.heima.article.service.ApArticleService;
import com.heima.client.article.IArticleClient;
import com.heima.model.common.dtos.ArticleDto;
import com.heima.model.common.dtos.CommentSaveDto;
import com.heima.model.common.dtos.ResponseResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.web.bind.annotation.*;

/**
 * @author 陈辉
 * @data 2024 16:12
 */
@RestController
@RequestMapping("/api/v1/article")
@Slf4j
public class ArticleClient {
    @Autowired
    private ApArticleService apArticleService;
    /**
     * 保存或修改article文章信息
     *
     * @param articleDto
     * @return
     */
    @PostMapping("/sync")
    public ResponseResult syncArticle(@RequestBody ArticleDto articleDto) {
        log.info("article文章同步开始了：{}....",articleDto);
       /* try {
            Thread.sleep(10000L);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }*/
        return apArticleService.saveOrUpdateArticle(articleDto);
    }

    /**
     * 查找作者信息
     *
     * @param articleId
     * @return
     */
    @PostMapping("/query/{articleId}")
    public ResponseResult queryArticle(@PathVariable Long articleId) {
        log.info("查找作者信息开始了：{}....",articleId);
        return apArticleService.queryArticle(articleId);
    }

    /**
     * 修改文章信息
     *
     * @param articleDto
     */
    @PostMapping("/update")
    public ResponseResult updateArticle(@RequestBody ArticleDto articleDto) {
        log.info("修改文章信息：{}....",articleDto);
        return apArticleService.updateArticle(articleDto);
    }

    /**
     * 存入文章的用户行为信息
     *
     * @param articleDto
     */
    @PostMapping("/behavior/update")
    @Async
    public ResponseResult behaviorArticle(@RequestBody ArticleDto articleDto) {
        log.info("存入文章的用户行为信息：{}....",articleDto);
        return apArticleService.behaviorArticle(articleDto);
    }


    /**
     * 查询文章是否可以评论
     * @param articleId
     * @return
     */
    @PostMapping("/api/v1/article/iscomment/{articleId}")
    public ResponseResult isComment(@PathVariable String articleId){
        log.info("查询文章是否可以评论：{}....",articleId);
        return apArticleService.isComment(articleId);
    }
}
